import React, {Component} from 'react';
import './comentItem.css'

import PropTypes from 'prop-types';


export default class CommentItem extends Component {

    static propTypes = {
        component: PropTypes.object.isRequired,
        deleteComment: PropTypes.func.isRequired,
        index: PropTypes.number.isRequired,
    }

    handleDeleteComment = () => {
        const {comment, index} = this.props
        if (window.confirm(`确认删除${comment.username}的评论吗??`)) {
            console.log(index);
            this.props.deleteComment(index)
        }
    }

    render() {
        const {comment} = this.props
        return (
            <li className="list-group-item">
                <div className="handle">
                    <a href="javascript:;"
                       onClick={this.handleDeleteComment}>删除</a>
                </div>
                <p className="user">
                    <span>{comment.username}</span><span>说:</span></p>
                <p className="centence">{comment.content}</p>
            </li>
        )
    }
}
